<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <script src="../node_modules/react/umd/react.development.js"></script>
    <script src="../node_modules/react-dom/umd/react-dom.development.js"></script>
    <script src="../node_modules/babel-standalone/babel.min.js"></script>
    <title>ref回调函数</title>
</head>

<body>
    <h1>ref回调函数</h1>
    <ol>
        <li></li>
    </ol>
    <hr />
    <div id="demoReact"></div>
</body>
<script src="../../node_modules/babel-standalone/babel.min.js"></script>
<script src="../../node_modules/react/umd/react.development.js"></script>
<script src="../../node_modules/react-dom/umd/react-dom.development.js"></script>
<script type="text/babel">

    class MyCom extends React.Component {

        constructor() {
            super();
            this.state = {
                inputValue: ""
            }
        }

        fun = () => {
            // console.log(this.textinput.value);
            this.setState({inputValue: this.textinput.value});
        }

        render() {
            return (
                <div>
                    <div>我是一个类组件</div>
                    <input type="text" ref={(inputObj) => { this.textinput = inputObj }} replaceholder="请输入" onInput={this.fun}/>
                    <p>输入框的值：{this.state.inputValue}</p>
                </div>
            )
        }
    }

    // 创建根节点
    let root = ReactDOM.createRoot(document.getElementById("demoReact"));

    // 渲染组件
    root.render(<MyCom />);
</script>

</html>